package java_class_work.week02;

import java.util.Random;
import java.util.Scanner;

/**
 * @Author Tiam
 * @Date 2022/9/19 10:05
 * @Description:
 */
public class Demo01 {
    public static void main(String[] args) {
        Random random = new Random();
        int number = random.nextInt(100);
        Scanner scanner = new Scanner(System.in);
        int guess, count = 5;
        do {
            System.out.print("请输入你猜的数字(你还有"+count+"次机会):");
            try {
                guess = scanner.nextInt();
            }catch (NumberFormatException e){
                System.out.println("大锅,请输入数字晓得不");
                continue;
            }
            if(guess == -1){
                System.out.println("Tips:(随机数是"+number+")");
            }
            count--;
            if (guess == number) {
                System.out.println("恭喜你猜对了,你猜了" + count + "次,随机数是" + number);
                break;
            }
            if(count==0){
                System.out.println("挑战失败!随机数是"+number);
                break;
            }
            if (guess > number) System.out.println("猜大了");
            else System.out.println("猜小了");
        } while (true);
    }
}
